package cn.pengpeng.cmcc.util


import com.typesafe.config.{Config, ConfigFactory}
import org.apache.kafka.common.serialization.StringDeserializer

/**
  * Created by root on 2018/9/28.
  */
object AppParams {
  /**
    * 解析application.conf
    */
  private lazy val load: Config = ConfigFactory.load()

  /**
    * 订阅主题
    */
  val topics: Array[String] = load.getString("kafka.topics").split(",")

  /**
    * kafka集群所在的主机以及端口
    */
  val broker: String = load.getString("kafka.broker.list")

  /**
    * 消费组id
    */
  val groupId: String = load.getString("kafka.group.id")

  /**
    * kafka相关参数
    */
  val kafkaParams: Map[String, Object] = Map[String, Object](
    "bootstrap.servers" -> broker,
    "key.deserializer" -> classOf[StringDeserializer],
    "value.deserializer" -> classOf[StringDeserializer],
    "group.id" -> groupId,
    "auto.offset.reset" -> "earliest",
    "enable.auto.commit" -> "false"
  )

  /**
    * redis 主机
    */
  val redisHost: String = load.getString("redis.host")
  val selectDBIndex: Int = load.getInt("redis.db.index")

  /**
    * 省份code和name的映射关系
    */
  import scala.collection.JavaConversions._
  val pcode2PName: Map[String, AnyRef] = load.getObject("pcode2pname").unwrapped().toMap

}
